<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateOrderDetailSplite extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        return ;
        for ($i = 0; $i <= 99; $i++) {

            $name = str_pad($i, 3, 0, STR_PAD_LEFT);

            Schema::connection("mysqlOrder")->create('order_detail_' . $name, function (Blueprint $table) use ($name) {
                $table->unsignedBigInteger('id')->default(0)->comment("主键 id");
                $table->unsignedInteger("brandId")->default(0)->comment("品牌 Id");
                $table->unsignedInteger("shopId")->default(0)->comment("店铺 ID");
                $table->unsignedBigInteger('orderId')->default(0)->comment("kf_orders表id");
                $table->unsignedInteger('productId')->default(0)->comment("菜品 Id");
                $table->string('productName', 50)->default('')->comment("菜品名");
                $table->unsignedInteger('menuId')->default(0)->comment("菜单 Id");
                $table->unsignedInteger('categoryId')->default(0)->comment("菜品分类 Id");
                $table->unsignedInteger('num')->default(0)->comment("菜品数量");
                $table->string('unit', 30)->default('')->comment("菜品单位");
                $table->unsignedInteger('originalUnitPrice')->default(0)->comment("原单价");
                $table->unsignedInteger('originalPrice')->default(0)->comment("原总价");
                $table->unsignedInteger('shouldUnitPrice')->default(0)->comment("应付单价");
                $table->unsignedInteger('payPrice')->default(0)->comment("应付总价");
                $table->unsignedInteger('refundNum')->default(0)->comment("退菜数量");
                $table->unsignedInteger('freeNum')->default(0)->comment("赠菜数量");
                $table->unsignedInteger('discountType')->default(0)->comment("优惠类型 1折扣 2减免");
                $table->unsignedInteger('discountNum')->default(0)->comment("优惠值 90折, 5元等");
                $table->unsignedInteger('discountPrice')->default(0)->comment("优惠价格");
                $table->tinyInteger('isDeleted')->default(0)->comment("是否删除 0：未删除，1：已删除");
                $table->string('imageUrl', 255)->default(0)->comment('菜品图片');

                // 统一表字段
                $table->integer('createdAt')->default(0)->comment('创建时间');
                $table->integer('createdByUid')->default(0)->comment('创建人');
                $table->integer('updatedAt')->default(0)->comment('修改时间');
                $table->integer('updatedByUid')->default(0)->comment('修改人');
                $table->string('updatedBy')->default(0)->comment('修改人');
                $table->string('createdBy')->default(0)->comment('创建人');

                // 索引部分
                $table->index('orderId', 'idx_orderId');  // 索引
                $table->index('createdAt', 'idx_createdAt');  // 索引
                $table->primary('id', 'idx_id');        // 主键非自增

                $table->collation = 'utf8mb4_general_ci';
                $table->comment   = '订单明细表_' . $name;
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        for ($i = 0; $i <= 99; $i++) {
            $name = str_pad($i, 3, 0, STR_PAD_LEFT);
            Schema::connection("mysqlOrder")->dropIfExists('order_detail_' . $name);
        }
    }
}
